package com.xls.commonlibrary.http.biz;

import android.text.TextUtils;

import com.orhanobut.logger.Logger;
import com.xls.commonlibrary.app.MainApplication;
import com.xls.commonlibrary.util.cache.ACache;

// 广告管理工具 like 间隔
public class AdControlUtil {
    private static volatile AdControlUtil singleton = null;

    private AdControlUtil() {
    }

    public static AdControlUtil getInstance() {
        if (singleton == null) {
            synchronized (AdControlUtil.class) {
                if (singleton == null) {
                    singleton = new AdControlUtil();
                }
            }
        }
        return singleton;
    }


    ////////////////////////////////////////////////////


    // 广告间隔
    int freshTime = 15;// XX  s后自动删除cache

    // 保存开始广告的时间
    public void saveStartTime(String tag) {
        ACache.get(MainApplication.getAppContext()).put(tag, System.currentTimeMillis() + "", freshTime);
    }

    // 清空
    public void clearStartTime(String tag) {
        ACache.get(MainApplication.getAppContext()).remove(tag);
    }

    // 是否可以显示下一条广告
    public boolean isAble2Show(String tag) {
        boolean result = true;

        String time = ACache.get(MainApplication.getAppContext()).getAsString(tag);
        Logger.d("======isAble2Show==========:%s", time);

        if (!TextUtils.isEmpty(time)) {
            // 不为空 说明还在倒计时内，不能看
            result = false;
        }

        return result;
    }

}
